(local M (: (require :lualine.component) :extend))
(set M.processing false)
(set M.spinner_index 1)
(local spinner-symbols ["⠋"
                        "⠙"
                        "⠹"
                        "⠸"
                        "⠼"
                        "⠴"
                        "⠦"
                        "⠧"
                        "⠇"
                        "⠏"])

(local spinner-symbols-len 10)
(fn M.init [self options]
  (M.super.init self options)
  (local group (vim.api.nvim_create_augroup :CodeCompanionHooks {}))
  (vim.api.nvim_create_autocmd [:User]
                               {:callback (fn [request]
                                            (if (= request.match
                                                   :CodeCompanionRequestStarted)
                                                (set self.processing true)
                                                (= request.match
                                                   :CodeCompanionRequestFinished)
                                                (set self.processing false)))
                                : group
                                :pattern :CodeCompanionRequest*}))

(fn M.update_status [self]
  (if self.processing
      (do
        (set self.spinner_index
             (+ (% self.spinner_index spinner-symbols-len) 1))
        (. spinner-symbols self.spinner_index))
      nil))

M

